package com.dycx.api.controller.manage.food;

import com.dycx.common.RestResponse;
import com.dycx.common.annotation.WriterLog;
import com.dycx.common.enums.BizTypeEnum;
import com.dycx.food.dto.GoodsClassDTO;
import com.dycx.food.service.GoodsClassFoodService;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import javax.validation.Valid;

@RestController
@RequestMapping(value = "/manage/food/goodsClass")
public class GoodsClassFoodController {

    @Resource
    private GoodsClassFoodService goodsClassService;

    /**
     * 添加
     **/
//    @WriterLog(bizType = BizTypeEnum.MALL_GOODS_CLASS, bizValue = "{#goodsClassDto.id}")
    @PostMapping("/insert")
    public RestResponse<?> insert(@RequestBody @Valid GoodsClassDTO goodsClassDto) {
        return goodsClassService.insert(goodsClassDto) ? RestResponse.success() : RestResponse.fail();
    }

    /**
     * 修改
     **/
    @WriterLog(bizType = BizTypeEnum.MALL_GOODS_CLASS, bizValue = "{#goodsClassDto.id}")
    @PostMapping("/update")
    public RestResponse<?> update(@RequestBody @Valid GoodsClassDTO goodsClassDto) {
        return goodsClassService.update(goodsClassDto) ? RestResponse.success() : RestResponse.fail();
    }

    /**
     * 刪除
     **/
    @WriterLog(bizType = BizTypeEnum.MALL_GOODS_CLASS, bizValue = "{#goodsClassId}")
    @GetMapping("/delete")
    public RestResponse<?> delete(int goodsClassId) {
        return goodsClassService.delete(goodsClassId) ? RestResponse.success() : RestResponse.fail();
    }


    /**
     * 查询 根据主键 id 查询
     **/
    @GetMapping("/getAllList")
    public RestResponse<?> getAllList() {
        return RestResponse.success(goodsClassService.getAllList(0, null));
    }

    /**
     * 修改排序
     **/
    @WriterLog(bizType = BizTypeEnum.MALL_GOODS_CLASS, bizValue = "{#goodsClassDto.id}")
    @PostMapping("/updateSort")
    public RestResponse<?> updateSort(@RequestBody GoodsClassDTO goodsClassDto) {
        return RestResponse.success(goodsClassService.updateSort(goodsClassDto));
    }

    /**
     * 修改状态
     **/
    @WriterLog(bizType = BizTypeEnum.MALL_GOODS_CLASS, bizValue = "{#goodsClassDto.id}")
    @PostMapping("/updateStatus")
    public RestResponse<?> updateStatus(@RequestBody GoodsClassDTO goodsClassDto) {
        return RestResponse.success(goodsClassService.updateStatus(goodsClassDto));
    }

    /**
     * 查询子类
     **/
    @GetMapping("/getListByParentId")
    public RestResponse<?> getListByParentId(Integer parentId) {
        return RestResponse.success(goodsClassService.getListByParentId(parentId));
    }
}
